package com.example.qxfw.backgroundManagement.service.impl;

import com.example.qxfw.backgroundManagement.mapper.UserManagementFirstMapper;
import com.example.qxfw.backgroundManagement.service.UserManagerFirstService;
import com.example.qxfw.common.entity.UserTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/4  星期二   9:27
 * @description : 此类用来 用户管理1的业务实现
 ***************************************/
@Service
public class UserManagerFirstServiceImpl implements UserManagerFirstService {

    private static final Logger logger = LoggerFactory.getLogger(UserManagementFirstMapper.class);

    @Autowired
    private UserManagementFirstMapper userManagementFirstMapper;



    @Override
    public List<UserTable> selectUserTable(final int pageNum) {
        int a = (pageNum - 1) * 19;
        List<UserTable> userTableList;
        if (a <= 0) {
            userTableList = this.userManagementFirstMapper.selectUserTableLimit19();
        } else {
            List<String> userNames = this.userManagementFirstMapper.selectUserTableLimitA(a);
            userTableList = this.userManagementFirstMapper.selectUserTable(userNames);
        }
        return userTableList;
    }

    @Override
    public Integer selectCountUserTable() {
        Integer integer = this.userManagementFirstMapper.selectNumber();
        logVerification("查询用户表的用户数量",integer);
        return integer;
    }

    @Override
    public List<UserTable> queryUserTable(final String startTime, final String endTime, final String userName) {
        List<UserTable> userTables = this.userManagementFirstMapper.queryUserTable(startTime, endTime, userName);
        return userTables;
    }

    @Override
    public List<UserTable> selectByUserName(final String userName) {
        List<UserTable> userTables = this.userManagementFirstMapper.selectUserName(userName);
        return userTables;
    }

    @Override
    public Integer saveUserTable(UserTable userTable) {
        Integer idMax = this.userManagementFirstMapper.selectIdMax();
        Integer insertUserTable = this.userManagementFirstMapper.insertUserTable( idMax,userTable);
        return insertUserTable;
    }

    @Override
    public Integer updateUserTable(final String userName, final String password, final String serviceWebAddress, final String serviceWechatAddress, final String inputTime, final String performer) {
        Integer updateUserTable = this.userManagementFirstMapper.updateUserTable(userName, password, serviceWebAddress, serviceWechatAddress, inputTime, performer);
        return  updateUserTable;
    }

    @Override
    public Integer deleteUserTable(final String userName) {
        Integer deleteUserTable = this.userManagementFirstMapper.deleteUserTable(userName);
        return deleteUserTable;
    }

    @Override
    public List<UserTable> exportUserTable() {
        List<UserTable> userTables = this.userManagementFirstMapper.selectAllForExport();
        return userTables;
    }



    public static void logVerification(String info, Object data) {
        logger.debug(info + " ------> " + data);
    }
}
